package com.softa.common.sysconfig.support;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.Collection;
import java.util.List;

/**
 *  列表定制
 * @author yangl
 *
 */
@Data
public class DataTableResponse {
	private long total;
	private Iterable<?> rows;

	public long iTotalRecords;
	public long iTotalDisplayRecords;
	private Iterable<?> aaData;
	public int sEcho;

	public DataTableResponse(Page<?> pageInfo, int sEcho) {
		this.aaData = pageInfo.getRecords();
		this.iTotalDisplayRecords = pageInfo.getTotal();
		this.iTotalRecords = pageInfo.getTotal();
		this.sEcho = sEcho;
		this.total = pageInfo.getTotal();
	}

	public DataTableResponse(Collection<?> rows, int sEcho) {
		this.aaData = rows;
		this.iTotalDisplayRecords = rows.size();
		this.iTotalRecords = rows.size();
		this.sEcho = sEcho;
		this.total = rows.size();
	}

	public DataTableResponse(long total, Iterable<?> rows) {
		super();
		this.total = total;
		this.rows = rows;
	}

	public DataTableResponse(Page<?> pageInfo) {
		this.setRows(pageInfo.getRecords());
		this.setTotal(pageInfo.getTotal());
	}

	public DataTableResponse(List<?> list) {
		if (list != null) {
			this.total = list.size();
			this.rows = list;
		}

	}

}
